﻿using System;
using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.NavBar;
using RFS.WPF.Views;
using RFS.WPF.Views.Settings;

namespace RFS.WPF
{




    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        
        SysVm _vm;

        public MainWindow(SysVm vm)
        {
            _vm = vm;
            
            InitializeComponent();

            ConfigureNavBarControl();
            
            // _vm.Loaded+= 

            DataContext = vm;

            _vm.RegisterDocument(MyMainDocGroup);
        }



        private void ConfigureNavBarControl()
        {
            var ms = _vm.MenutItems;
            
            foreach (var menuItem in ms)
            {
                
                var  group1 = new NavBarGroup()
                {
                    Header    = menuItem.Title,
                    FontSettings = new FontSettings(){ FontSize = 16, FontWeight = FontWeight.FromOpenTypeWeight(50) }
                    
                };

             

               
  
                foreach (var si in menuItem.SubItems)
                {
                    var sa=new NavBarItem()
                    {
                        Content =$"    {si}",
                        
                    } ;

                    group1.Items.Add(sa);
                    sa.Command = _vm.CmdNevBarItemExcute;
                    sa.CommandParameter = si;
                }


                // Add groups to the NavBarControl
                NavBarControl.Groups.Add(group1);
          
            }
         
        }
        void Runb(Action act)
        {
            
            Cursor= Cursors.Wait;
            try
            {
                act?.Invoke();
            }
            finally
            {
                Cursor= Cursors.Arrow;

            }
            
        }


 
        private void UIElement_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                // _vm.CmdSearch.Execute();
            }
        }


        private void ButtonBasePrice_OnClick(object sender, RoutedEventArgs e)
        {
            // Runb(() =>
            // {
            //     var v = new Price();
            //     v.ShowDialog();                
            //     
            //     
            // });
            
            PopupSettingWin.IsOpen=true;
            

        }

        private void ButtonBasePriceSetting_OnClick(object sender, RoutedEventArgs e)
        {
            
             Runb(() =>
             {

                 var v = new Price();
                 v.ShowDialog();
                 
             });
        }
    }
}
